package cn.cxy.demo

import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import cn.cxy.demo.MyService
import cn.cxy.demo.R

class MainActivity : AppCompatActivity() {

    private lateinit var serviceIntent: Intent
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        //启动Service
        serviceIntent = Intent(this, MyService::class.java)
        startService(serviceIntent)
    }

    override fun onDestroy() {
        super.onDestroy()
        //停止Service
        stopService(serviceIntent)
    }
}